require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
var userInfo=JSON.parse(sessionStorage.getItem("userInfo"));
var dataInfo=JSON.parse(sessionStorage.getItem("data"));
if(!userInfo){
    location.href="/loginIndex"
}
var vm = new Vue({
    el:"#authentication",
    data:{
        state:"",  //0未申请 1审核中2不通过 3通过
        loginUid:userInfo.id,
        idType:"",
        idFront:"",
        idBack:"",
        idNum:"",
        name:"",
        imgNum1:1,
        imgNum2:1,
        results1:"",
        results2:"",
        dataInfo:dataInfo,
        idTypeName:""
    },
    mounted:function(){
        this.searchObject = this.getQueryStringArgs();
        this.state=this.searchObject&&this.searchObject.state;
        //this.getBlackList();
    },
    methods:{
        //后退
        getBack:function(){
            location.href="/happyi";
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        getChange:function(type){
            var that=this,coverImgSrc;
            if(type==1){
                coverImgSrc=document.getElementById("fileinput1").files[0];//$("#fileinput").files[0];
            }else if(type==2){
                coverImgSrc=document.getElementById("fileinput2").files[0];//$("#fileinput").files[0];
            }
            lrz(coverImgSrc, function (results) {
                // 你需要的数据都在这里，可以以字符串的形式传送base64给服务端转存为图片。
                console.log(results);
                if(type==1){
                    that.results1=results;
                    that.imgNum1=2;
                    that.idFront=coverImgSrc;//$("#fileinput").files[0];
                }else if(type==2){
                    that.results2=results;
                    that.imgNum2=2;
                    that.idBack=coverImgSrc;//$("#fileinput").files[0];
                }
                //demo_report(results.base64);
            });
        },
        //下拉框选择
        getSelect:function(num){
            var that=this,type;
            type="hk_user_IdType";
            var arr={};
            var data=[];
            that.dataInfo.dict.forEach(function(val,key){
                if(val.type==type){
                    arr={};
                    arr.id=val.id;
                    arr.value=val.label;
                    data.push(arr);
                }
            });
            var bankSelect = new IosSelect(1,
                [data],
                {
                    container: '.provingMode',
                    itemHeight: 30,
                    itemShowCount: 3,
                    callback: function (selectOneObj) {
                        console.log(selectOneObj)
                        that.idType=selectOneObj.id;
                        that.idTypeName=selectOneObj.value;
                    }
                });
        },
        //实名认证
        applyRealName:function(){
            var that=this;
            if(that.idType&&that.idFront&&that.idBack&&that.idNum&&that.name){
                if(!that.idType){
                    vm.$refs.prompt.toast("请选择证件类型！");
                    return;
                }
                if(!that.name){
                    vm.$refs.prompt.toast("请输入真实姓名！");
                    return;
                }
                if(!that.idNum){
                    vm.$refs.prompt.toast("请输入证件号码！");
                    return;
                }else{
                    var regIdNo = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
                    if(!regIdNo.test(that.idNum)){
                        vm.$refs.prompt.toast("身份证号填写有误！");
                        return false;
                    }
                }
                if(!that.idFront){
                    vm.$refs.prompt.toast("证件正面照不能为空！");
                    return;
                }
                if(!that.idBack){
                    vm.$refs.prompt.toast("证件反面照不能为空！");
                    return;
                }
            }else{
                vm.$refs.prompt.toast("信息填写不全！");
            }
            var formData = new FormData();
            formData.append("loginUid", that.loginUid);
            formData.append("idType", that.idType);
            formData.append("idFront",that.idFront);
            formData.append("idBack", that.idBack);
            formData.append("idNum", that.idNum);
            formData.append("name", that.name);

            console.log(formData)
            $.ajax({
                url:host+'/v1/user/applyRealName',   //http://192.168.100.104:8083
                type:'POST',
                data:formData,
                dataType:'json',
                async: false,
                cache: false,
                contentType: false, //不设置内容类型
                processData: false, //不处理数据
                success:function(data){
                    console.log(data);
                    location.href="/happyi/authentication?state=1";
                },
                error:function(){
                    vm.$refs.prompt.toast("实名认证失败！");
                }
            });
        },
        getNext:function(){
           location.href="/happyi/realNameProtocol";
        }
    },
    watch:{
        idNum:function(){

        }
    }

});
function demo_report(src) {
    var img = new Image();
    img.onload=function(){
        vm.data.coverImgWidth = img.width;
        vm.data.coverImgHeight = img.height;

    };
    $(".circleSetup-cover").append(img);
    img.src = src;
}